package com.zbj.validator.common;

import com.zbj.validator.enums.ResultCode;

/**
 * @author weigang
 * @create 2017-04-12
 **/
public class Results {

    /**
     * 构造成功response
     *
     * @return
     */
    public static Result<String> success() {
        return success("success");
    }

    /**
     * 构造成功response
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> success(T data) {
        Result<T> result = Result.create();
        result.success(data);
        result.setCode(ResultCode.SUCCESS.getCode());
        result.setDescription(ResultCode.SUCCESS.getDescription());
        return result;
    }

    /**
     * 构造失败response
     *
     * @param desc 失败描述
     * @return
     */
    public static <T> Result<T> fail(String desc) {
        return fail(ResultCode.FAIL.getCode(), desc);
    }

    public static <T> Result<T> fail(ResultCode resultCode) {
        return fail(resultCode.getCode(), resultCode.getDescription());
    }

    /**
     * 构造失败response
     *
     * @param code 失败码
     * @param desc 失败描述
     * @return
     */
    public static <T> Result<T> fail(String code, String desc) {
        return fail(code, desc, null);
    }

    /**
     * 构造失败response
     *
     * @param code 失败码
     * @param desc 失败描述
     * @return
     */
    public static <T> Result<T> fail(String code, String desc, T data) {
        Result<T> result = Result.create();
        result.fail(code, desc);
        result.setData(data);
        return result;
    }

}
